package com.ctrip.cap.amqp;

import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.QueueingConsumer;

public class ConListener {
	public static void Start(String queueName) {
		try {

			ConnectionFactory factory = new ConnectionFactory();
		    factory.setHost("csm-haddop03.dev.sh.ctripcorp.com");
		    factory.setUsername("admin");
		    factory.setPassword("123456");
		    
		    Connection connection = (Connection) factory.newConnection();
		    Channel channel = connection.createChannel();
			
			QueueingConsumer consumer = new QueueingConsumer(channel);
		    channel.basicConsume(queueName, true, consumer);

		    while (true) {
		      QueueingConsumer.Delivery delivery = consumer.nextDelivery();
		      String message = new String(delivery.getBody());
		      System.out.println(" [x] Received '" + message + "'");
		    }
		} catch (Exception e) {
			
		}
	}

}
